from time import sleep
from page_locators.evaluation_moral_education_locator import EvaluationMoralEducateLocator as EML
from common.base_page import BasePage
from test_datas.name_datas import *


class EvaluationMoralEducate(BasePage):

    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    def evaluation_system_click(self, username, password):
        self.click(EML.login_click, '登录界面点击失败截图')
        self.input(EML.username_loc, username, '用户名输入失败截图')
        self.input(EML.password_loc, password, '密码输入失败截图')
        # code = self.get_code(EML.captcha_img, '验证码图片定位', 'src')
        # self.input(EML.captcha, code, '验证码输入')
        self.click(EML.loginsbt, '登录按钮点击失败截图')
        self.click(EML.workbench_loc, '我的工作台定位失败截图')
        sleep(1)
        self.switch_window()
        sleep(5)
        # self.click(EML.cancel_password_change, '取消修改密码按钮定位失败截图')
        self.click(EML.evaluation, "德育评价系统点击跳转")
        sleep(1)

    def evaluation_menu_click(self):
        self.switch_window()
        sleep(5)
        self.click(EML.evaluation_menu, "德育评价菜单定位点击")

    def choice_grade1_class1(self):
        self.click(EML.grade_box, "年级下拉框定位点击")
        self.click(EML.grade1, "一年级定位点击")
        self.choice_class1()

    def choice_grade4_class1(self):
        self.click(EML.grade_box, "年级下拉框定位点击")
        self.click(EML.grade4, "四年级定位点击")
        self.choice_class1()

    def choice_class1(self):
        self.click(EML.class_box, "班级下拉框定位点击")
        self.click(EML.class1, "1班定位点击")

    def choices_names(self):
        grade = self.get_text(EML.list1_grade, "列表第一个年级标签定位取值")
        if grade == "二年级":
            choices_names = choices_names1
            return choices_names
        elif grade == "五年级":
            choices_names = choices_names2
            return choices_names
        else:
            self.logger.error("请选择一年级1班或四年级1班")

    def input_name1(self):
        names = self.choices_names()
        name = names[0]
        self.name_len_judge(name)

    def name_len_judge(self, name):
        if len(name) == 3:
            a = name[:1]
            b = name[1:2]
            c = name[2:]
            self.input(EML.input_name, a, "名称输入框定位输入")
            self.input(EML.input_name, b, "名称输入框定位输入")
            self.input(EML.input_name, c, "名称输入框定位输入")
        elif len(name) == 2:
            a = name[:1]
            b = name[1:]
            self.input(EML.input_name, a, "名称输入框定位输入")
            self.input(EML.input_name, b, "名称输入框定位输入")
        else:
            self.input(EML.input_name, name, "名称输入框定位输入")

    def input_name2(self):
        names = self.choices_names()
        name = names[1]
        self.name_len_judge(name)

    def input_name3(self):
        names = self.choices_names()
        name = names[2]
        self.name_len_judge(name)

    def input_name4(self):
        names = self.choices_names()
        name = names[3]
        self.name_len_judge(name)

    def input_name5(self):
        names = self.choices_names()
        name = names[4]
        self.name_len_judge(name)

    def input_name6(self):
        names = self.choices_names()
        name = names[5]
        self.name_len_judge(name)

    def input_name7(self):
        names = self.choices_names()
        name = names[6]
        self.name_len_judge(name)

    def input_name8(self):
        names = self.choices_names()
        name = names[7]
        self.name_len_judge(name)

    def input_name9(self):
        names = self.choices_names()
        name = names[8]
        self.name_len_judge(name)

    def input_name10(self):
        names = self.choices_names()
        name = names[9]
        self.name_len_judge(name)

    def click_hand_evaluate(self):
        self.click(EML.manual_evaluation, "手动评价按钮定位点击")

    def eval_index_box_click(self):
        self.click(EML.eval_index, "评价指标下拉框点击")

    def choice_index(self):
        self.eval_index_box_click()
        sleep(1)
        self.click_index()

    # 五个维度中随机选择一个维度点击,五个观测点中随机选择一个点击, 但是需注意每个维度下都需要有最少五个观测点
    def click_index(self):
        index = (EML.index1, EML.index2, EML.index3, EML.index4, EML.index5)
        tip = (EML.tip1, EML.tip2, EML.tip3, EML.tip4, EML.tip5)
        choices_index = choices(index, k=1)
        choices_tip = choices(tip, k=1)
        self.suspension_loc(choices_index[0], choices_tip[0], "指标观测点定位点击")

    def add_score(self):
        self.clear(EML.add_score, "清空默认分值")
        self.input(EML.add_score, 1, "分值加1")

    def click_sure_sub(self):
        self.click(EML.sure, "确定按钮定位点击")

    def eval_grade1_class1_name1(self):
        self.choice_grade1_class1()
        self.input_name1()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade1_class1_name2(self):
        self.choice_grade1_class1()
        self.input_name2()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade1_class1_name3(self):
        self.choice_grade1_class1()
        self.input_name3()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade1_class1_name4(self):
        self.choice_grade1_class1()
        self.input_name4()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade1_class1_name5(self):
        self.choice_grade1_class1()
        self.input_name5()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade1_class1_name6(self):
        self.choice_grade1_class1()
        self.input_name6()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade1_class1_name7(self):
        self.choice_grade1_class1()
        self.input_name7()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade1_class1_name8(self):
        self.choice_grade1_class1()
        self.input_name8()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade1_class1_name9(self):
        self.choice_grade1_class1()
        self.input_name9()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade1_class1_name10(self):
        self.choice_grade1_class1()
        self.input_name10()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade4_class1_name1(self):
        self.choice_grade4_class1()
        self.input_name1()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade4_class1_name2(self):
        self.choice_grade4_class1()
        self.input_name2()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade4_class1_name3(self):
        self.choice_grade4_class1()
        self.input_name3()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade4_class1_name4(self):
        self.choice_grade4_class1()
        self.input_name4()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade4_class1_name5(self):
        self.choice_grade4_class1()
        self.input_name5()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade4_class1_name6(self):
        self.choice_grade4_class1()
        self.input_name6()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade4_class1_name7(self):
        self.choice_grade4_class1()
        self.input_name7()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade4_class1_name8(self):
        self.choice_grade4_class1()
        self.input_name8()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade4_class1_name9(self):
        self.choice_grade4_class1()
        self.input_name9()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()

    def eval_grade4_class1_name10(self):
        self.choice_grade4_class1()
        self.input_name10()
        sleep(1)
        self.click_hand_evaluate()
        self.choice_index()
        self.add_score()
        self.click_sure_sub()


